## Plot Distributions of Block Milieus in Modal Counties
## (Paper Figures 4 and 5)
## Andrew Reeves and Ryan T. Moore
## First: 9 February 2017
## Last: 19 January 2020

## Load libraries:
library(ggplot2)

## Load data:
load("figures4and5.Rdata")
modal.counties <- c("37021", "08059", "37183", "36047", "36061", "06037", "49035", "06075", "17031")

for(i in 1:length(modal.counties)){
  df <- subset(opLocsModal, opLocsModal$county.fips.1 == modal.counties[i])
  df.tmp <- subset(df, df$county.fips == modal.counties[i])
  main.title <- paste(df.tmp$namelsad10.county[1], ", ", df.tmp$state.abb[1], sep = "")
  abline.point <- (1 - df.tmp$pctwhite.cty[1]) * 100
  fn <- paste(df.tmp$name10.county[1], df.tmp$state.abb[1], ".pdf", sep = "")
  tmp.hist <- ggplot(df, aes(x = (1 - pctwhite)*100, fill = uid, weight = pop100/ttl.dyn.pop)) + 
    geom_density(alpha = .3)  + 
    geom_vline(xintercept = abline.point) +
    xlab("Percent Non-White") + labs(title = main.title) + theme(legend.position = "none") +
    theme(plot.title = element_text(size = rel(3))) 
  
  pdf(file = fn)
  print(tmp.hist)
  dev.off()
}

